package com.example.designmode.strategyPattern;

import java.math.BigDecimal;

public class FullSubtract extends Strategy{

    //单价
    private double unitPrice;
    //数量
    private double number;
    //满足满多少金额
    private double full;
    //减多少金额
    private double subtract;

    //使用全参构造填充数据
    public FullSubtract(double unitPrice, double number, double full, double subtract) {
        this.unitPrice = unitPrice;
        this.number = number;
        this.full = full;
        this.subtract = subtract;
    }

    //计算逻辑 如果花费的金额超过或者等于当前制定的满减金额 减满减活动金额
    @Override
    double AlgorithmInterface() {
        BigDecimal money
                = new BigDecimal(unitPrice).multiply(new BigDecimal(number));
        if (money.doubleValue() >= full){
            return money.subtract(new BigDecimal(subtract)).doubleValue();
        }
        return money.doubleValue();
    }
}
